package cn.topevery.garden.wapi.controller;

import cn.topevery.garden.dal.logic.GardenTestLogic;
import cn.topevery.garden.entity.dto.GardenTestDTO;
import cn.topevery.garden.entity.po.GardenTest;
import cn.topevery.garden.entity.query.GardenTestQuery;
import hw.topevery.framework.db.entity.DataPager;
import hw.topevery.framework.util.ExcelUtil;
import hw.topevery.framework.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * 
 *
 * @author code-generate
 * @date 2021-08-06
 */
@Api(tags = "")
@RestController
@RequestMapping("/gardenTest")
public class GardenTestController extends BaseController {


    @Autowired
    GardenTestLogic gardenTestLogic;

    /**
     * 获取分页列表
     *
     * @param query
     * @return
     */
    @ApiOperation(value = "获取页列表")
    @PostMapping("/listPage")
    public JsonResult<DataPager<GardenTest>> listPage(@RequestBody GardenTestQuery query) {
        return JsonResult.ok(gardenTestLogic.listPage(query));
    }

    @ApiOperation("新增/编辑 信息")
    @PostMapping("/saveOrUpdate")
    public JsonResult<Boolean> saveOrUpdate(@Valid @RequestBody GardenTestDTO dto) {
        return JsonResult.ok(true);//gardenTestLogic.saveOrUpdate(getUser().userId,dto));
    }


    @ApiOperation("根据自增ID批量删除")
    @PostMapping("/deleteBatchById")
    public JsonResult<Boolean> deleteBatchById(@RequestBody Integer[] ids) {
        gardenTestLogic.deleteBatchById(getUser().userId,ids);
        return JsonResult.ok(true);
    }

    @ApiOperation("导出信息")
    @GetMapping("/export")
    public void export(GardenTestQuery query, HttpServletResponse response) {
        List<GardenTest> list = gardenTestLogic.listPage(query).records;
        ExcelUtil.exportExcel(list, "", "sheet1", GardenTest.class, "", response);
    }

}
